package com.example.task.service;

import com.example.task.entity.HttpTask;
import com.example.task.repository.HttpTaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskService {

    @Autowired
    private HttpTaskRepository repository;

    public List<HttpTask> getAll() {
        return repository.findAll();
    }

    public void save(HttpTask task) {
        repository.save(task);
    }

    public void delete(Long id) {
        repository.deleteById(id);
    }

    public List<HttpTask> getActiveTasks() {
        return repository.findByActiveTrue();  // 注意此方法需在 repository 中定义
    }

    public HttpTask get(Long id) {
        return repository.findById(id).orElse(null);
    }

}
